<?php
/**
 * CodeIgniter - Controller - Welcome
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * Controller - Upload Questions
 *
 * @package		CodeIgniter
 * @subpackage	Controller
 * @category	Controller
 * @author		PHPTest
 * @link		NA
 */
 
class Upload_Questions extends Controller 
{
	var $view_array = array();
	var $view_item 	= 'upload_questions';	
	var $page_title = 'Online Test - PHP, Mysql, CSS, JavaScript - Upload New Questions';
	
	// --------------------------------------------------------------------------
	
	/** 
	 * Upload Questions - Constructor
	 *
	 * @access 		public
	 * @category	function
	 * @param  		NA	 
	 * @return 		void
	 */	
	function Upload_Questions()
	{
		parent::Controller();
		check_user_login();	
	}
	
	// --------------------------------------------------------------------------
	
	/** 
	 * Index
	 *
	 * @access 		public
	 * @category	function
	 * @param  		NA	 
	 * @return 		void
	 */	
	function index()
	{		
		
    }
	
	// ------------------------------------------------------------------------	
		
	/**
	 * Excel
	 *
	 * @category	function
	 * @access 	public
	 * @param	string
	 * @param 	string
	 * @return 	string
	 *
	 */
	function excel()
	{
		/*
		This library reads an Excel formatted spreadsheet document.  Currently it only works with newer versions of Excel but will be made to work with older versions in time.		
		The library is made for CI 1.5 or newer and currently does not depend on any other CI libraries or helpers.  Just place the library file in the libraries folder and load it as normal.  Its usage is a bit limited right now, once the spreadsheet is read you can access each worksheet as a two-dimensional array.  
		Currently this array is a jagged array, that is, it only reflects the cells from the worksheet that contain data, not the empty ones.  
		this is the intended usage:
		*/
		// Load the spreadsheet reader library
		$this->load->library('excel_reader');
		$file = ROOTBPATH.'uploads/file2.xls';
		if(is_file($file))
		{
			// Read the spreadsheet via a relative path to the document
			// for example $this->excel_reader->read('./uploads/file.xls');
			$this->excel_reader->read($file);
			
			// Get the contents of the first worksheet
			$worksheet = $this->excel_reader->worksheets[0]; 
			$cnt_data = count($worksheet);
			if(is_array($worksheet) &&  $cnt_data > 0)
			{
				// start from from 1 element as wwe don't want 0 element data
				for($i=1 ; $i < $cnt_data ; $i++)
				{
					$qus = htmlentities(addslashes(trim($worksheet[$i][0])),ENT_QUOTES,'UTF-8');
					$op1 = htmlentities(addslashes(trim($worksheet[$i][1])),ENT_QUOTES,'UTF-8');
					$op2 = htmlentities(addslashes(trim($worksheet[$i][2])),ENT_QUOTES,'UTF-8');
					$op3 = htmlentities(addslashes(trim($worksheet[$i][3])),ENT_QUOTES,'UTF-8');
					$op4 = htmlentities(addslashes(trim($worksheet[$i][4])),ENT_QUOTES,'UTF-8');
					$ans = (int) trim($worksheet[$i][5]);
					$wei = (int) trim($worksheet[$i][6]);	
					
					echo '<br/>--'.$qus.'--'.$op1.'--'.$op2.'--'.$op3.'--'.$op4.'--'.$ans.'--'.$wei;				
				}				
			}
		}
		else
			echo 'Oops!! Soory the file you are trying to upload does not exists.<br/>File Path : '.$file;
	}
}//EOF Controller Upload Questions
?>